package com.clstu.homeworks;

import java.util.Scanner;

public class HomeWork02 {
    public static void main(String[] args) {
        try {
            assign();
            System.out.println("邮箱登录成功");
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
    public static void assign(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名");
        String name=sc.next();
        if(name.length()>4||name.length()<2){
            throw new RuntimeException("用户名长度不对");
        }
        System.out.println("请输入密码");
        String pwd=sc.next();
        if(!(isDigit(pwd))){
            throw new RuntimeException("密码输入错误");
        }
        System.out.println("请输入邮箱");
        String yx=sc.next();
        if(!(isEmail(yx))){
            throw new RuntimeException("邮箱输入有误");
        }
    }
    public static boolean isDigit(String s){
        if(s.length()!=6) return false;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)>'9'||s.charAt(i)<0){
                return false;
            }
        }
        return true;
    }

    public static boolean isEmail(String s){
        int a=-1;
        int b=-1;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='@'&&a==-1){
                a=i;
            }
            if(s.charAt(i)=='.'&& b==-1){
                b=i;
            }

        }
        if(a<b&&a!=-1&&b!=-1) return true;
        return false;
    }
}
